package com.rslai.base.tool.servertest.config;

import com.rslai.base.tool.servertest.annotation.ConfigElement;
import com.rslai.base.tool.servertest.annotation.Element;
import com.rslai.base.tool.servertest.annotation.Property;
import com.rslai.base.tool.servertest.command.AssertStepCommand;
import com.rslai.base.tool.servertest.command.StepCommand;
import com.rslai.base.tool.servertest.model.KeyValueStore;
import com.rslai.base.tool.servertest.util.CloneUtil;

import java.util.List;

import org.apache.commons.lang.StringUtils;

@ConfigElement(defaultProperty = "body")
public class AssertStepConfig extends StepConfig {
    public static final String BODY_TAG_NAME = "body";

    @Property(defaultValue = "")
    private String desc;

    @Property
    private String body;

    @Element
    List<KeyValueStore> params;

    public StepCommand createCommand() {
        appendBodyIfExists();
        return new AssertStepCommand(CloneUtil.cloneKeyValueStore(this.params), this.desc);
    }

    private void appendBodyIfExists() {
        if (StringUtils.isNotBlank(this.body))
            this.params.add(new KeyValueStore("body", this.body));
    }
}